import fetchNode from 'isomorphic-fetch'
import { isDevelopment } from "../utils/env";
import { lConfig } from "../config/config";
// const fetchNode = require('node-fetch');

export const fetch = {
  get (url) {
    return fetchNode(url, {
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
      }
    })
  },
  post (url, body: any = {}) {
    return fetchNode(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
      },
      body: JSON.stringify(body)
    })
  },
}

const basicUrl = `${ lConfig.adminServer }/public`
export const basic = {
  get (url, params) {
    console.log('GET URL: ', `${basicUrl}/${url}`)
    return fetch.get(`${basicUrl}/${url}`)
  },
  post (url, { body, params }: any = {}) {
    // const body = { body, params }
    console.log('POST URL: ', `${basicUrl}/${url}`)
    return fetch.post(`${basicUrl}/${url}`, body)
  }
}
